// pages/detail/detail.js
var app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        shop_name: '幸福缘商城',
        URL: app.globalData.url,
        menu: [{
            name: '商品',
            action: true,
        }, {
            name: '详情',  
            action: false,
        }, {
            name: '评价',
            action: false,
        }],
        goods: {
            name: '狄豪（DIHAO）沙发 真皮沙发 大小户型组合皮沙发客厅家具 双位+贵妃',
            price: 5977.00,
            blurb: '【家装盛宴】全场1件9折/2件8.5折/3件8折，买沙发送2个皮凳子，详情咨询客服！',

        },
        containerBlock: [
            'block', 'none', 'none'
        ],
        bannerList: [{
            img: 'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
            id: 10
        }, {
            img: 'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
            id: 11
        }, {
            img: 'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg',
            id: 12
        }],
        think: [{
            name: '匿名用户',
            score: 3,
            content: '手感不错，感觉是羊毛，里面还有草叶子，送人的，希望她喜欢。',
            piclist: [
                'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
                'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
                'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg',
                'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg'
            ],
            time: '2016-11-5'
        }, {
            name: '匿名用户2',
            score: 5,
            content: '手感不错，萨达萨达大所多撒多撒多撒多撒多撒多撒多撒大所大所大所多撒大所里面还有草叶子，送人的，希望她喜欢。',
            piclist: [
                'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
                'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
                'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
            ],
            time: '2016-11-11'
        }, {
            name: '匿名用户',
            score: 3,
            content: '手感不错，感觉是羊毛，里面还有草叶子，送人的，希望她喜欢。',
            piclist: [
                'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
                'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
                'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg',
                'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg'
            ],
            time: '2016-11-5'
        }, {
            name: '匿名用户2',
            score: 5,
            content: '手感不错，萨达萨达大所多撒多撒多撒多撒多撒多撒多撒大所大所大所多撒大所里面还有草叶子，送人的，希望她喜欢。',
            piclist: [
                'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
                'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
                'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
            ],
            time: '2016-11-11'
        }, ]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
      // console.log(options.id);
      var goods_id = options.id;
      var that = this;
      console.log(goods_id);
        wx.request({
          url: 'http://shop.yougou520.cn/api/shop/goods_detail',
          method:"POST",
          data:{
            // id: goods_id,
            id:418,
          },
          success:function(res){
            console.log(res.data);
            that.setData({
              goods: {
                name: res.data.goods.goods_name,
                price: res.data.goods.shop_price,
                blurb: res.data.goods.goods_remark,
              },
              bannerList: res.data.goods_images_list,
            });
          }
        })

        var that = this;
        app.getUrl(options);
        wx.getSystemInfo({
            success: function(res) {
                // console.log(res.model)
                // console.log(res.pixelRatio)
                    // console.log(res.windowWidth)
                    // console.log(res.windowHeight)
                    // console.log(res.language)
                    // console.log(res.version)
            }
        })
        wx.getLocation({
            type: 'wgs84',
            success: function(res) {
                wx.request({
                    url: 'http://apis.map.qq.com/ws/geocoder/v1/?location=' + res.latitude + ',' + res.longitude + '&key=XUBBZ-BY76D-I7644-PQZI3-5BVWV-XBBPN',
                    success: function(ret) {
                        // console.log(ret.data.result.address_component);
                        that.setData({
                            addr: ret.data.result.address_component
                        });
                    }
                });
                var latitude = res.latitude
                var longitude = res.longitude
                var speed = res.speed
                var accuracy = res.accuracy
                // console.log(res);
            }
        })
    },
    /**
     * 调用全局返回函数 
     */
    returnPage: function(e) {
        app.returnPage(e);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },
    /**
     * 内容容器变换
     */
    toContainer: function(e) {
        var that = this;
        // console.log(e.currentTarget.dataset.id);
        var index = e.currentTarget.dataset.id;
        for (var i in that.data.menu) {
            if (i == index) {
                that.data.menu[i].action = true;
                that.data.containerBlock[i] = 'block';
            } else {
                that.data.menu[i].action = false;
                that.data.containerBlock[i] = 'none';
            }
        }
        that.setData({
            menu: that.data.menu,
            containerBlock: that.data.containerBlock
        });

    },
    /**
     * 调用全局页面跳转函数
     */
    goToPage: function(e) {
        app.goToPage(e);
    }

})